package com.basic.boot.web.dto;

import com.basic.boot.web.model.User;
import com.basic.boot.web.service.DTOConvert;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * @author cherrish
 * @time 2019-03-18 10:33
 * @name UserDTO
 * @desc:
 */
@Data
public class UserDTO {
    private String username;
    private String password;
    private Byte age;
    private Byte sex;

    public User convert2User(){
        return new UserDTOConvert().convert(this);
    }

    /**
     * 自定义实现
     */
    private static class UserDTOConvert implements DTOConvert<UserDTO, User>{
        @Override
        public User convert(UserDTO dto) {
            User user = new User();
            BeanUtils.copyProperties(dto, user);
            return user;
        }
    }
}
